package cn.itcast.customview.Actrvity;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.View;
import android.view.animation.BounceInterpolator;
import android.widget.Button;
import android.widget.ImageView;

import cn.itcast.customview.R;

public class PropertyAnimationActivity extends AppCompatActivity {

    private Button btn_property;
    private ImageView iv_animation;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_property_animation);

        btn_property=(Button)findViewById(R.id.btn_property);
        iv_animation=(ImageView)findViewById(R.id.iv_animation);

        btn_property.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

//                view.setTranslationY();
                ObjectAnimator animator=ObjectAnimator.ofFloat(iv_animation,"translationY",0,iv_animation.getWidth());
                ObjectAnimator animator1=ObjectAnimator.ofFloat(iv_animation,"translationX",0,iv_animation.getHeight());

                AnimatorSet animatorSet=new AnimatorSet();
                animatorSet.playTogether(animator,animator1);
                animatorSet.setDuration(2000);
                animatorSet.setInterpolator(new BounceInterpolator());//回弹效果
                animatorSet.start();



            }
        });

    }
}
